﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的第一个angular项目</title>
    <script src="https://cdn.bootcss.com/angular.js/1.7.8/angular.js"></script>

</head>
<body>
<h1>计算商品价格</h1>
<div ng-app="buy" ng-controller="control">
    <p>
        <button ng-click="decr()">-</button>
        <input type="text" ng-model="num">
        <button ng-click="incr()">+</button>
    </p>
    <p>总价：{{num*8}}</p>
</div>
</body>
<script>
    const app = angular.module('buy', []);
    app.controller('control',function($scope){
        $scope.num =1
        $scope.incr = function(){
            this.num +=1;
        }

        $scope.decr = function(){
            if(this.num > 1){
                this.num -=1;
            }
        }
    });

</script>
</html>
